package com.novellotus.iov.carvice.adapter;

import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.novellotus.iov.carvice.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Rich on 2017/7/25.
 */

public class CarAlarmAdapter extends RecyclerView.Adapter<CarAlarmAdapter.CarAlarmHolder> {

    private int alarmLevel;
    private List<String> alarm = new ArrayList<>();

    public CarAlarmAdapter(int alarmLevel, List<String> alarm) {
        this.alarmLevel = alarmLevel;
        this.alarm = alarm;
    }

    @Override
    public CarAlarmAdapter.CarAlarmHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_alarm, null);
        return new CarAlarmHolder(view);
    }

    @Override
    public void onBindViewHolder(CarAlarmAdapter.CarAlarmHolder holder, int position) {
        switch (alarmLevel) {
            case 1:
                holder.tv_alarm.setBackgroundResource(R.drawable.shape_alpha_corners_alarm_level_one);
                holder.tv_alarm.setTextColor(Color.parseColor("#f7be0e"));
                break;
            case 2:
                holder.tv_alarm.setBackgroundResource(R.drawable.shape_alpha_corners_alarm_level_two);
                holder.tv_alarm.setTextColor(Color.parseColor("#f66038"));
                break;
            case 3:
                holder.tv_alarm.setBackgroundResource(R.drawable.shape_alpha_corners_alarm_level_three);
                holder.tv_alarm.setTextColor(Color.parseColor("#ed3760"));
                break;
        }
        holder.tv_alarm.setText(alarm.get(position));
    }

    @Override
    public int getItemCount() {
        return alarm.size();
    }

    class CarAlarmHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_alarm)
        TextView tv_alarm;

        public CarAlarmHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

}
